import { Http } from "../../utils/http"
import { Order } from "../../model/Order"

Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabs: [{
      id: 0,
      name: "全部",
      isActive: true,
      start: "all"
    },
    {
      id: 1,
      name: "今天",
      isActive: false,
      start: "today"
    },
    {
      id: 2,
      name: "昨天",
      isActive: false,
      start: "yesterday"
    },
    {
      id: 3,
      name: "近七日",
      isActive: false,
      start: "week"
    }],
    doctorData: [],
    allData: [],
    todayData: [],
    yesterdayData: [],
    weekData: [],
    start: 'all',
    has_more: true,//是否还有数据
    count: '',//共多少笔订单
    brokerage: "",//总收益
    countNo:''//为支付订单
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: async function (options) {
    let result = await Order.get_distributor_spred_list('all',100);
    let http = Http.login();
    console.log(result);
    if (result.code == 0) {
      this.setData({
        allData: result.data.order.data,
        has_more: result.data.has_more,
        count: result.data.count,
        brokerage: result.data.brokerage,
        countNo:result.data.count_
      })

    }
  },

  /**
   * 页面上拉触底事件的处理函数e.currentTarget.dataset.start == 'week' ||
   */
  onReachBottom: function () {
  },
  onChange: async function (e) {
    console.log(e.detail.index);
    let result;
    if (e.detail.index == 0) {
      result = await Order.get_distributor_spred_list('all',100);
      if (result.code == 0) {
        this.setData({
          allData: result.data.order.data,
          has_more: result.data.has_more,
          count: result.data.count,
          brokerage: result.data.brokerage
        })
      }
    } else if (e.detail.index == 1) {
      result = await Order.get_distributor_spred_list('today',100);
      if (result.code == 0) {
        this.setData({
          todayData: result.data.order.data,
          has_more: result.data.has_more,
          count: result.data.count,
          brokerage: result.data.brokerage
        })

      }
    } else if (e.detail.index == 2) {
      result = await Order.get_distributor_spred_list('yesterday',100);
      console.log(result);
      if (result.code == 0) {
        this.setData({
          yesterdayData: result.data.order.data,
          has_more: result.data.has_more,
          count: result.data.count,
          brokerage: result.data.brokerage
        })

      }
    } else if (e.detail.index == 3) {
      result = await Order.get_distributor_spred_list('week',100);
      if (result.code == 0) {
        this.setData({
          weekData: result.data.order.data,
          has_more: result.data.has_more,
          count: result.data.count,
          brokerage: result.data.brokerage
        })

      }
    }
  }
})